<?php
$appLinks = Blyn::app()->getUIManager()->getLinks();
$createSpaceLink = $appLinks['createSpace']['ajaxUrl'];
$joinSpaceLink = $appLinks['joinSpace']['ajaxUrl'];
$apps = Blyn::app()->getActiveSpace()->getApps();
$activeApp = Blyn::app()->getActiveApp();

$items = array();
$item = array();

$displayName = Blyn::app()->getActiveSpace()->getName(BEntity::Name_DisplayName);

if (Blyn::app()->getActiveOperation() != NULL) {
    $currentOperation = Blyn::app()->getActiveOperation();
    if ($currentOperation->getId() == Blyn::app()->getCurrentUser()->getPersonalSpace()->
                    getAppByName('BPersonalApp')->getOperation(BPersonalApp::OPERATION_CREATESpace)->getId()) {
        $displayName = Yii::t('site', 'Create Your Space');
    }
    if ($currentOperation->getId() == Blyn::app()->getCurrentUser()->getPersonalSpace()->
                    getAppByName('BPersonalApp')->getOperation(BPersonalApp::OPERATION_JOINSpace)->getId()) {
        $displayName = Yii::t('site', 'Space Store');
    }
    if ($currentOperation->getId() == Blyn::app()->getCurrentUser()->getPersonalSpace()->
                    getAppByName('BPersonalApp')->getOperation(BPersonalApp::OPERATION_LISTMYSpace)->getId()) {
        $displayName = Yii::t('site', 'My Spaces');
    }
}

//array_push($items, $item);
foreach ($apps as $app) {

    $name = $app->getName();

    if ($name == 'SpaceEngine' || $name == 'BSpaceEngine') {
        $name = Yii::t('site', 'Home');
    } else {
        $name = Yii::t('site', $name);
    }

    if ($app->getId() != Blyn::app()->getCurrentUser()->getPersonalSpace()->getAppByName('BPersonalApp')->getId()) {
        //$item['url'] = $app->getUIManager()->getUrl(array('ajaxLink' => array('name' => $name)));
        $item['url'] = $app->getUIManager()->getAjaxLink($name);
        $item['label'] = $name;
        $item['active'] = '';

        if ($app->getId() == $activeApp->getId())
            $item['active'] = 'active';

        array_push($items, $item);
    }
}
?>

<div id="SpaceTopBar">
    <div>
        <div class="container" style="margin: auto;margin-top: 0px;padding-top: 15px">
            <div class="row-fluid">
                <div class="span3">
                    <h4 style="color: whitesmoke"> <?php echo $displayName; ?></h4>
                </div>
                <div class="span2"></div>
                <div class='span6'>               
                    <div class="btn-toolbar" style="padding-top: 10px">
                        <?php echo $createSpaceLink; ?>    
                        <?php echo $joinSpaceLink; ?>    
                        <?php
                        $control = new BUIThemedControl('allApp');
                        echo $control->getLink('经典界面', array(
                            'cooker' => 'BAEventCooker@showEventList',
                            'theme' => 'a_bootstrap',
                            'htmlOptions'=>array('class'=>'btn btn-warning','target'=>'_blank')
                        ))
                        ?>
                    </div>               
                </div>
            </div> 
            <?php if (Blyn::app()->getActiveApp()->getId() != Blyn::app()->getCurrentUser()->getPersonalSpace()->getAppByName('BPersonalApp')->getId()) { ?>
                <ul class="nav nav-tabs blue-backgroud-link" style="margin-bottom: 0;">
                    <?php foreach ($items as $item) { ?>
                        <li class="<?php echo $item['active']; ?>">
                            <?php echo $item['url']; ?>
                        </li>  
                    <?php } ?>
                    <li><?php
                        $control = new BUIThemedControl('allApp');
                        $control->getLink('所有应用', array(
                            'cooker' => 'BAEventCooker@showEventList',
                            'theme' => 'a_bootstrap',
                            'htmlOptions'
                        ))
                        ?></li>
                </ul>
            <?php } ?>
        </div>
    </div>
</div>

